package es.uclm.itsue.dosd;
import java.util.Timer;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Bundle;
import android.view.View;

public class ViewInvalidateActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(new myGraphicsView(this));
	}

	static public class myGraphicsView extends View {

		private Bitmap mBitmap, bird;
		private Matrix matrix = new Matrix();
		float x=240; float y=300; float d=0;
		
		Timer updateTimer = new Timer();
		
		public myGraphicsView(Context context) {
			
			super(context);
			
			mBitmap = BitmapFactory.decodeResource(
					getResources(), R.drawable.red_angry_bird);
			bird = Bitmap.createScaledBitmap(
					mBitmap, 100, 100, false);
		
		}
		
		@Override 
		protected void onDraw(Canvas canvas) {
			
	    	canvas.drawColor(Color.BLACK);
	    	
	    	matrix.reset();
			matrix.postTranslate(x, y);
			matrix.postRotate(d, 
					x + bird.getWidth()  / 2, 
					y + bird.getHeight() / 2);

	        canvas.drawBitmap(bird, matrix, null);
	        
	        x += 10;	if (x > 480) x = 0;
	        d += 10;	if (d >= 360) d = 0;
	        
			invalidate();
		}
	
	}
}

